<template>
  <section class="form-section">
    <el-form ref="form" :model="form" :rules="rules" label-width="130px">
      <el-form-item label="设置新密码:" prop="password">
        <el-input placeholder="请输入密码" v-model="form.password" />
      </el-form-item>
      <el-form-item label="再次输入新密码:" prop="password2">
        <el-input placeholder="请再次输入密码" v-model="form.password2" />
      </el-form-item>
      <div style="text-align:center">
        <el-button class="login-btn" type="primary" @click="onNext">下一步</el-button>
      </div>
    </el-form>
  </section>
</template>

<script>
  export default {
    name: 'ForgetStep2',
    data() {
      return {
        form: {
          password: '',
          password2: ''
        },
        rules: {
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { min: 6, message: '密码长度不小于6个字符', trigger: 'blur' }
          ],
          password2: [
            { required: true, message: '请再次输入密码', trigger: 'blur' }
          ]
        }
      };
    },

    methods: {
      async onNext() {
        const valid = await this.$refs.form.validate();
        if (!valid) return;
        const data = { ...this.form };
        this.$emit('next', data);
      }
    },
    created() {}
  };
</script>

<style lang="scss" type="text/scss" scoped>
.form-section {
  display: flex;
  justify-content: center;
  .el-form {
    width: 400px;
    color: white;
    background: white;
    .el-input {
      width: 100%;
    }
    .login-btn {
      width: 130px;
      margin-top: 12px;
    }
  }
}
</style>
